package com.jason.kotlin.gank.viewmodel

import android.app.Application
import androidx.lifecycle.viewModelScope
import com.jason.kotlin.gank.api.GankService
import com.jason.kotlin.gank.model.GankDataBean
import com.jason.kotlin.gank.repository.GankApiImpl
import com.jason.library.common.base.BasePageViewModel
import com.jason.library.common.base.DataWrapper
import kotlinx.coroutines.launch

/**
 * @description: GanHuoViewModel
 *
 * @author ChenBaoyang
 * @date 4/20/21 10:33
 */
class GanHuoViewModel(application: Application) : BasePageViewModel<GankDataBean>(application) {

    private var gankApi = GankApiImpl()

    var type: String = ""

    override fun loadData(page: Int) {
        viewModelScope.launch {
            try {
                val response = gankApi.loadCategoryData(GankService.CATEGORY_GANHUO, type, page, 20)

                data.postValue(DataWrapper.success(response.data))

                showContent()
            }catch (e: Exception) {
                showError(e.toString())
            }
        }
    }
}